import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Solution151 {
    /**
     * 给定一个字符串，逐个翻转字符串中的每个单词。
     * <p>
     * <p>
     * <p>
     * 示例 1：
     * <p>
     * 输入: "the sky is blue"
     * 输出: "blue is sky the"
     */
    public String reverseWords(String s) {
        String[] res = s.trim().split(" ");
        StringBuilder sb = new StringBuilder();
        for (int i = res.length - 1; i >= 0; i--) {
            String tem = res[i].trim();
            if (tem.equals("")) continue;
            sb.append(tem).append(" ");
        }
        return sb.length() == 0 ? "" : sb.substring(0, sb.length() - 1);
    }
}
